package stack.ExerciseClass;

import java.util.Scanner;

public class TenToTwo {

    public StringBuffer transform(int n /*表示十进制*/,int m/*表示要转换为多少进制*/){
        String str="";
        if(m==2||m==8){
            while (true){
                int temp = n % m;
                str+=temp;
                n=n/m;
                if(n==0){
                    break;
                }
            }
        }
       if(m==16){
           if(n==10){
               str="A";
               return new StringBuffer(str);
           }
           if(n==11){
               str="B";
               return new StringBuffer(str);
           }
           if(n==12){
               str="C";
               return new StringBuffer(str);
           }
           if(n==13){
               str="D";
               return new StringBuffer(str);
           }
           if(n==14){
               str="E";
               return new StringBuffer(str);
           }
           if(n==15){
               str="F";
               return new StringBuffer(str);
           }
           while (true){
               int temp = n % m;
               str+=temp;
               n=n/m;
               if(n==0){
                   break;
               }
           }
       }
        StringBuffer s = new StringBuffer(str);
        s.reverse();
        return s;
    }

    public static void main(String[] args) {
        TenToTwo t = new TenToTwo();

        Scanner s = new Scanner(System.in);

        System.out.print("请输入您要转化的数的十进制:");

        int n = s.nextInt();

        System.out.print("请输入您要转换为什么进制:");

        int m = s.nextInt();

        StringBuffer transform = t.transform(n, m);
        System.out.println(transform);
    }
}
